package marcel.display
{
	import com.greensock.easing.Expo;
	import com.greensock.OverwriteManager;
	import com.greensock.plugins.AutoAlphaPlugin;
	import com.greensock.plugins.TintPlugin;
	import com.greensock.plugins.TweenPlugin;
	import com.greensock.TweenLite;
	import flash.display.DisplayObjectContainer;
	import flash.geom.Point;
	
	public class Tween
	{
		// see TweenLite doc http://www.greensock.com/as/docs/tween/
		
		public static var DEFAULT_EASE:Function = Expo.easeOut;
		__init();
		
		public function Tween(o:ConstructorAccess) {}
		
		public static function moveTo(obj:Object, position:Point, time:Number = 1, ease:Function = null, delay:Number = 0, param:Object = null):TweenLite
		{
			
			var _params:Object = __initProps(ease, delay, param);
			_params.x = position.x;
			_params.y = position.y;
			return TweenLite.to(obj, time, _params);
		}
		
		public static function resizeTo(obj:Object, size:Point, time:Number = 1, easing:Function = null, delay:Number = 0, param:Object = null):TweenLite
		{
			var _params:Object = __initProps(easing, delay, param);
			_params.width = size.x;
			_params.height = size.y;
			return TweenLite.to(obj, time, _params);
		}
		
		public static function alphaTo(obj:Object, alpha:Number = 1, time:Number = 1, easing:Function = null, delay:Number = 0, checkVisible:Boolean = false, param:Object = null):TweenLite
		{
			var _params:Object = __initProps(easing, delay, param);
			_params[checkVisible ? "autoAlpha" : "alpha"] = alpha;
			return TweenLite.to(obj, time, _params);
		}
		
		public static function colorTo(obj:Object, color:Number, time:Number = 1, easing:Function = null, delay:Number = 0, extra:Object = null):TweenLite
		{
			var _params:Object = __initProps(easing, delay, extra);
			_params.tint = color;
			return TweenLite.to(obj, time, _params);
		}
			
		public static function removeTweens(target:Object, removeChildrenTweens:Boolean = false):void 
		{
			TweenLite.killTweensOf(target);
			if (removeChildrenTweens && (target is DisplayObjectContainer)) {
				var _nbChild:Number = (target as DisplayObjectContainer).numChildren;
				for (var i:int = 0; i < _nbChild; i++) removeTweens((target as DisplayObjectContainer).getChildAt(i), true);
			}
		}
		
		private static function __init():void
		{
			TweenPlugin.activate([AutoAlphaPlugin, TintPlugin]);
			OverwriteManager.init(0);
		}
		
		private static function __initProps(ease:Function = null, delay:Number = 0, param:Object = null):Object {
			if (param === null) param = {};
			param.ease = (ease === null) ? DEFAULT_EASE : ease;
			param.delay = delay;
			return param;
		}
	}
}

internal class ConstructorAccess {}